package com.ruoyi.training.service.impl;

import java.util.List;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.training.util.xuehua.SnowflakeIdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.training.mapper.A02ResMateralMapper;
import com.ruoyi.training.domain.A02ResMateral;
import com.ruoyi.training.service.IA02ResMateralService;

import javax.annotation.Resource;

/**
 * 材料库Service业务层处理
 * 
 * @author WorrilessGo
 * @date 2025-11-18
 */
@Service
public class A02ResMateralServiceImpl implements IA02ResMateralService 
{
    @Resource
    private A02ResMateralMapper a02ResMateralMapper;

    /**
     * 查询材料库
     * 
     * @param materalId 材料库主键
     * @return 材料库
     */
    @Override
    public A02ResMateral selectA02ResMateralByMateralId(String materalId)
    {
        return a02ResMateralMapper.selectA02ResMateralByMateralId(materalId);
    }

    /**
     * 查询材料库列表
     * 
     * @param a02ResMateral 材料库
     * @return 材料库
     */
    @Override
    public List<A02ResMateral> selectA02ResMateralList(A02ResMateral a02ResMateral)
    {
        return a02ResMateralMapper.selectA02ResMateralList(a02ResMateral);
    }

    /**
     * 新增材料库
     * 
     * @param a02ResMateral 材料库
     * @return 结果
     */
    @Override
    public int insertA02ResMateral(A02ResMateral a02ResMateral)
    {
        a02ResMateral.setCreateTime(DateUtils.getNowDate());
        String id = String.valueOf(new SnowflakeIdUtils(5, 8).nextId());
        a02ResMateral.setMaterialId(id);
        return a02ResMateralMapper.insertA02ResMateral(a02ResMateral);
    }

    /**
     * 修改材料库
     * 
     * @param a02ResMateral 材料库
     * @return 结果
     */
    @Override
    public int updateA02ResMateral(A02ResMateral a02ResMateral)
    {
        a02ResMateral.setUpdateTime(DateUtils.getNowDate());
        return a02ResMateralMapper.updateA02ResMateral(a02ResMateral);
    }

    /**
     * 批量删除材料库
     * 
     * @param materalIds 需要删除的材料库主键
     * @return 结果
     */
    @Override
    public int deleteA02ResMateralByMateralIds(String[] materalIds)
    {
        return a02ResMateralMapper.deleteA02ResMateralByMateralIds(materalIds);
    }

    /**
     * 删除材料库信息
     * 
     * @param materalId 材料库主键
     * @return 结果
     */
    @Override
    public int deleteA02ResMateralByMateralId(String materalId)
    {
        return a02ResMateralMapper.deleteA02ResMateralByMateralId(materalId);
    }

    @Override
    public int batchInsertA02ResMateralByMateral(List<A02ResMateral> list) {
        list.forEach(s->{
            s.setMaterialId(String.valueOf(new SnowflakeIdUtils(5, 8).nextId()));
        });
        return a02ResMateralMapper.batchInsertA02ResMateralByMateral(list);
    }
}
